package br.com.aquinoevasconcelos.servlets.administrador;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import br.com.aquinoevasconcelos.fachada.Fachada;

/**
 * Servlet implementation class SairAdministrador
 */
@WebServlet("/SairAdministrador")
public class SairAdministrador extends HttpServlet {
	private static final long serialVersionUID = 1L;
  
    public SairAdministrador() {
        super();

    }
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	
    	Fachada fachada = Fachada.getInstancia();
    	try {
			
    		
    		HttpSession session = request.getSession();
    		session.invalidate();
    		System.out.println("sessão Encerrada!!");
    		response.sendRedirect("Index");
    		
    		
		} catch (Exception e) {
			response.sendRedirect("pagina_erro/erro.jsp");
			e.printStackTrace();
		}
    	
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		service(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		service(request, response);
	}

}
